using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.User
{
    public class UserResultHistoryDB
    {
        public UserResultHistoryDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        //public Int64 Insert(UserResultHistory userresulthis)
        //{
        //    MyDatabase _db = new MyDatabase();
        //    Int64 _result = -1;
        //    string _spName = "[sprocUserConfirmationInsertUpdateSingleItem]";

        //    SortedList _sPara = new SortedList();

        //    #region Parameter
        //    _sPara.Add("@UserConfirmationId", userresulthis.UserConfirmationId);
        //    _sPara.Add("@ConfirmationType", userresulthis.ConfirmationType);
        //    _sPara.Add("@UserResultId", userresulthis.UserResultId);
        //    _sPara.Add("@IsConfirm", userresulthis.IsConfirm);
        //    _sPara.Add("@CurrentStep", userresulthis.CurrentStep);
        //    _sPara.Add("@IsComplete", userresulthis.IsComplete);
        //    _sPara.Add("@ResultStatus", userresulthis.ResultStatus);
        //    _sPara.Add("@FirstStepId", userresulthis.FirstStepId);
        //    _sPara.Add("@RefCEUserId", userresulthis.RefCEUserId);

        //    _sPara.Add("@Status", userresulthis.Status);
        //    //_sPara.Add("@Info1", template.Info1);
        //    //_sPara.Add("@Info2", template.Info2);
        //    //_sPara.Add("@Info3", template.Info3);
        //    //_sPara.Add("@Info4", template.Info4);
        //    //_sPara.Add("@Info5", template.Info5);
        //    //_sPara.Add("@Info6", template.Info6);
        //    //_sPara.Add("@Info7", template.Info7);
        //    //_sPara.Add("@Info8", template.Info8);
        //    //_sPara.Add("@Info9", template.Info9);
        //    //_sPara.Add("@Info10", template.Info10);
        //    //_sPara.Add("@Info11", template.Info11);
        //    //_sPara.Add("@Info12", template.Info12);
        //    //_sPara.Add("@Info13", template.Info13);
        //    //_sPara.Add("@Info14", template.Info14);
        //    //_sPara.Add("@Info15", template.Info15);
        //    //_sPara.Add("@Info16", template.Info16);
        //    //_sPara.Add("@Info17", template.Info17);
        //    //_sPara.Add("@Info18", template.Info18);
        //    //_sPara.Add("@Info19", template.Info19);
        //    //_sPara.Add("@Info20", template.Info20);
        //    #endregion

        //    _result = _db.ExecuteSP(_spName, _sPara);

        //    return _result;
        //}

        public bool Update()
        {
            return true;
        }

        public bool Delete(Int64 RefCEUserId, Int64 UserResultId, string ResultType, string RowGUID)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocUserResultDeleteSingleItem]";
            int _result = 0;
            SortedList _sPara = new SortedList();

            _sPara.Add("@UserResultID", UserResultId);
            _sPara.Add("@RowGUID", RowGUID);
            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@ResultType", ResultType);
            _result = _db.ExecuteNonSqlSP(_spName, _sPara);
            return _result > 0;
        }

        public DataTable GetResultHistoryTable(Int64 RefCEUserId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocUserResultHistorySelectItemList]";
            SortedList _sPara = new SortedList();

            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@ResultType", ResultType);

            return _db.GetDataTableBySP(_spName, _sPara);
        }

        public UserResultHistory GetResultHistory(Int64 RefCEUserId, Int64 UserResultId, string ResultType, string RowGUID)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocUserResultSelectSingleItem]";
            UserResultHistory _result = null;
            SortedList _sPara = new SortedList();

            _sPara.Add("@UserResultID", UserResultId);
            _sPara.Add("@RowGUID", RowGUID);
            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@ResultType", ResultType);

            DataTable _dt = _db.GetDataTableBySP(_spName, _sPara);
            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = FillDataRecord(_dt, 0);
            }
            return _result;
        }

        public UserResultHistoryList GetResultHistoryList(Int64 RefCEUserId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocUserResultSelectItemList]";
            UserResultHistoryList _result = null;
            SortedList _sPara = new SortedList();

            _sPara.Add("@RefCEUserId", RefCEUserId);
            _sPara.Add("@ResultType", ResultType);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _sPara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _result = new UserResultHistoryList();
                    int _rowcount = _dt.Rows.Count;
                    for (int i = 0; i < _rowcount; i++)
                    {
                        UserResultHistory _usrresult = new UserResultHistory();
                        _usrresult = FillDataRecord(_dt, i);
                        _result.Add(_usrresult);
                    }
                }
            }

            return _result;
        }

        private UserResultHistory FillDataRecord(DataTable myDataTable, int RowId)
        {
            UserResultHistory myresult = new UserResultHistory();
            myresult.UserResultID = Convert.ToInt64(myDataTable.Rows[RowId]["UserResultID"].ToString());
            myresult.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myresult.ResultType = myDataTable.Rows[RowId]["ResultType"].ToString();
            myresult.FinishStep = Convert.ToInt32(myDataTable.Rows[RowId]["FinishStep"].ToString());
            myresult.TotalStep = Convert.ToInt32(myDataTable.Rows[RowId]["TotalStep"].ToString());
            myresult.IsComplete = Convert.ToBoolean(myDataTable.Rows[RowId]["IsComplete"].ToString());

            if (myDataTable.Rows[RowId]["ID1"] != null && myDataTable.Rows[RowId]["ID1"] != DBNull.Value)
                myresult.ID1 = Convert.ToInt64(myDataTable.Rows[RowId]["ID1"].ToString());

            if (myDataTable.Rows[RowId]["ID2"] != null && myDataTable.Rows[RowId]["ID2"] != DBNull.Value)
                myresult.ID2 = Convert.ToInt64(myDataTable.Rows[RowId]["ID2"].ToString());

            if (myDataTable.Rows[RowId]["ID3"] != null && myDataTable.Rows[RowId]["ID3"] != DBNull.Value)
                myresult.ID3 = Convert.ToInt64(myDataTable.Rows[RowId]["ID3"].ToString());

            if (myDataTable.Rows[RowId]["ID4"] != null && myDataTable.Rows[RowId]["ID4"] != DBNull.Value)
                myresult.ID4 = Convert.ToInt64(myDataTable.Rows[RowId]["ID4"].ToString());

            if (myDataTable.Rows[RowId]["ID5"] != null && myDataTable.Rows[RowId]["ID5"] != DBNull.Value)
                myresult.ID5 = Convert.ToInt64(myDataTable.Rows[RowId]["ID5"].ToString());

            if (myDataTable.Rows[RowId]["ID6"] != null && myDataTable.Rows[RowId]["ID6"] != DBNull.Value)
                myresult.ID6 = Convert.ToInt64(myDataTable.Rows[RowId]["ID6"].ToString());

            if (myDataTable.Rows[RowId]["ID7"] != null && myDataTable.Rows[RowId]["ID7"] != DBNull.Value)
                myresult.ID7 = Convert.ToInt64(myDataTable.Rows[RowId]["ID7"].ToString());

            if (myDataTable.Rows[RowId]["ID8"] != null && myDataTable.Rows[RowId]["ID8"] != DBNull.Value)
                myresult.ID8 = Convert.ToInt64(myDataTable.Rows[RowId]["ID8"].ToString());

            if (myDataTable.Rows[RowId]["ID9"] != null && myDataTable.Rows[RowId]["ID9"] != DBNull.Value)
                myresult.ID9 = Convert.ToInt64(myDataTable.Rows[RowId]["ID9"].ToString());

            if (myDataTable.Rows[RowId]["ID10"] != null && myDataTable.Rows[RowId]["ID10"] != DBNull.Value)
                myresult.ID10 = Convert.ToInt64(myDataTable.Rows[RowId]["ID1RowId"].ToString());

            myresult.RowGUID = myDataTable.Rows[RowId]["rowguid"].ToString();

            myresult.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());

            myresult.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myresult;
        }

    }
}